import * as types from "./mutation-types";
import Api from "api/api";

const state = {
  mergeFormData: {}, // 提交的表单对象
  formItemChildren: {} //动态表格的items对象,包含上级表单id
};

const getters = {
  mergeFormData: state => state.mergeFormData,
  formItemChildren: state => state.formItemChildren
};

const actions = {
  // 合并数据
  mergeFormDataAction({ commit }, param) {
    commit(types.MERGE_FORM_DATA, param);
  },
  // 删除某个属性
  delFormDataAction({ commit }, param) {
    commit(types.DEL_FORM_DATA, param);
  },
  // 更新动态表格的items对象
  updateFormItemChildren({ commit }, param) {
    commit(types.UPDATE_FORM_ITEM_CHILDREN, param);
  }
};

const mutations = {
  [types.MERGE_FORM_DATA](state, payload) {
    state.mergeFormData = Object.assign({}, state.mergeFormData, payload);
  },
  [types.DEL_FORM_DATA](state, payload) {
    delete state.mergeFormData[payload]
  },
  [types.UPDATE_FORM_ITEM_CHILDREN](state, payload) {
    state.formItemChildren = payload;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
